package com.crm.service.impl.productManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.productManager.CustomerMemberProductCourseMapper;
import com.crm.model.entity.productManager.CustomerMemberProductCourse;
import com.crm.model.entity.productManager.CustomerMemberProductCourseExample;
import com.crm.service.productManager.CustomerMemberProductCourseDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/5/11 17:03
 */
@Service
public class CustomerMemberProductCourseDbServiceImpl implements CustomerMemberProductCourseDbService {

    @Autowired
    private CustomerMemberProductCourseMapper customerMemberProductCourseMapper;

    /***
     * @Description:插入会员产品课程
     * @Param: 会员产品课程对象
     * @Author: luojie
     * @Date: 2021/5/12 9:50
     */
    @Override
    public Boolean insertCustomerMemberProductCourse(CustomerMemberProductCourse customerMemberProductCourse) {
        int num = customerMemberProductCourseMapper.insertSelective(customerMemberProductCourse);
        return num>0;
    }

    /***
     * @Description:根据会员产品服务项id查询会员产品课程
     * @Param: memberProductRelationId 会员产品服务项id
     * @Author: luojie
     * @Date: 2021/5/12 9:54
     */
    @Override
    public List<CustomerMemberProductCourse> selectMemberProductCourseByRelationId(String memberProductRelationId) {
        CustomerMemberProductCourseExample customerMemberProductCourseExample = new CustomerMemberProductCourseExample();
        CustomerMemberProductCourseExample.Criteria criteria = customerMemberProductCourseExample.createCriteria();
        criteria.andMemberProductRelationIdEqualTo(memberProductRelationId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberProductCourse> customerMemberProductCourseList = customerMemberProductCourseMapper.selectByExample(customerMemberProductCourseExample);
        return customerMemberProductCourseList;
    }

    /**
     * 根据主键删除服务项课程
     * @param customerMemberProductCourse 课程
     * @return
     */
    @Override
    public Boolean updateMemberProductCourseByCourseId(CustomerMemberProductCourse customerMemberProductCourse) {
        int num = customerMemberProductCourseMapper.updateByPrimaryKeySelective(customerMemberProductCourse);
        return num>0;
    }
}
